package com.atguigu.l_concurrentModificationException;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

public class Test {
    public static void main(String[] args) {
//        List<String> list = new ArrayList<>();

        // 使用vector
//        Vector<String> list = new Vector<>();

        // 使用collections辅助工具类
//        List<String> list = Collections.synchronizedList(new ArrayList<>());

        // 使用juc的写时复制-list
//        List<String> list = new CopyOnWriteArrayList<>();
//        Set<String> set = new CopyOnWriteArraySet<String>();
        Map<String, String> map = new ConcurrentHashMap<>();
        for (int i = 0; i < 10; i++) {
            new Thread(()-> {
                String s = UUID.randomUUID().toString().substring(0, 5);
                map.put(Thread.currentThread().getName(),s);
                System.out.println(map);
            }).start();

        }
    }
}
